package cn.iocoder.yudao.module.crm.dal.mysql.task;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.task.vo.TaskPageReqVO;
import cn.iocoder.yudao.module.crm.dal.dataobject.task.TaskDO;
import org.apache.ibatis.annotations.Mapper;

/**
 * CRM 任务单 Mapper
 *
 * @author 广州氪量
 */
@Mapper
public interface TaskMapper extends BaseMapperX<TaskDO> {

    default PageResult<TaskDO> selectPage(TaskPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<TaskDO>()
                .eqIfPresent(TaskDO::getCode, reqVO.getCode())
                .betweenIfPresent(TaskDO::getIssueTime, reqVO.getIssueTime())
                .eqIfPresent(TaskDO::getTaskTypeId, reqVO.getTaskTypeId())
                .eqIfPresent(TaskDO::getCustomerId, reqVO.getCustomerId())
                .eqIfPresent(TaskDO::getContractId, reqVO.getContractId())
                .eqIfPresent(TaskDO::getProductId, reqVO.getProductId())
                .eqIfPresent(TaskDO::getUserId, reqVO.getUserId())
                .betweenIfPresent(TaskDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(TaskDO::getId));
    }

    default Long selectTaskTypeIdById(Long id) {
        return selectOne(TaskDO::getId, id).getTaskTypeId();
    }
}